<?php

namespace App\Modules\OfficialAccount\Models;

use DB;
use Illuminate\Database\Eloquent\Model;
use Redis;

class ForceSubscribeUsers extends Model
{
    protected $tables = 'force_subscribe_users';

    protected $fillable = ['uid', 'official_account_id', 'distribution_channel_id', 'appid', 'openid', 'is_subscribed', 'subscribe_time', 'unsubscribe_time', 'last_interactive_time', 'bid', 'send_order_id'];

    static function getSubscribleCount($distribution_channel_ids, $date)
    {
        $obj = DB::table('official_accounts')->orderBy('id');
        if ($distribution_channel_ids) {
            $obj->whereIn('distribution_channel_id', $distribution_channel_ids);
        }
        $res = 0;
        $official_accounts = $obj->get();
        foreach ($official_accounts as $official_account) {
            $count = Redis::scard('gzh_new_sub:' . ($official_account->appid) . ':' . $date);
            \Log::info('gzh_new_sub:' . ($official_account->appid) . ':' . $date . $count);
            $res += $count;
        }
        return $res;
    }
}
